FROM docker.epwk.tech/base/composer:latest AS builder

LABEL maintainer="chenwenlong <chenwenlong@epweike.com>"

ENV COMPOSER_REPO_PACKAGIST https://packagist.laravel-china.org

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

RUN composer config -g repo.packagist composer ${COMPOSER_REPO_PACKAGIST}

RUN composer create-project playbloom/satisfy /var/www/satisfy --ignore-platform-reqs

FROM php:7.2-apache

COPY sources.list /etc/apt/sources.list

RUN apt-get update -q \
    && apt-get install -qy git cron supervisor \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN apt-get update -q \
    && apt-get install -qy vim \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

#COPY conf/supervisord.conf /etc/supervisord.conf
COPY --from=builder /var/www/satisfy/docker/conf/supervisor/* /etc/supervisor/conf.d/
COPY --from=builder /var/www/satisfy/docker/conf/apache.conf /etc/apache2/sites-available/000-default.conf
COPY --from=builder /var/www/satisfy /var/www/satisfy
COPY ./conf/cron.conf /etc/cron.d/satisfy

RUN echo "Asia/Shanghai" > /etc/timezone && \
    /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

RUN echo "date.timezone = PRC" >> /usr/local/etc/php/conf.d/php.ini \
    && chmod 644 /etc/cron.d/satisfy \
    && ln -s /usr/local/bin/php /usr/bin/php

RUN a2enmod rewrite

COPY ./satis.json /var/www/satisfy

#RUN mkdir /var/www/.composer && mkdir /var/www/.ssh && mkdir -p /var/lib/php/sessions && chown -R www-data:www-data /var/lib/php
RUN mkdir -p /var/lib/php/sessions && chown -R www-data:www-data /var/lib/php \
    && chown -R www-data:www-data /var/www/satisfy
#VOLUME /var/www/.composer
#VOLUME /var/www/.ssh

# symbolic links to index.php and static files
ARG APP_PATH=/var/www/satisfy

###########################################################################
# git:
###########################################################################
COPY ./gitconf /root
COPY ./gitconf /home/www-data

WORKDIR /var/www/satisfy

ENTRYPOINT ["supervisord", "-n"]

EXPOSE 80